<%-- 
    Document   : home
    Created on : Jun 18, 2012, 11:11:47 AM
    Author     : Home
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="dbTool.functions"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="../css1/styles.css" rel="stylesheet" type="text/css" />
        <script src="../js/jquery.min.js" type="text/javascript"></script>
        <script src="../js/dropmenu.js" type="text/javascript"></script>

        <script type="text/javascript" src="../js/jquery-1.2.6.min.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-personalized-1.5.2.packed.js"></script>
        <script type="text/javascript" src="../js/sprinkle.js"></script>
        <title>Administrator</title>
        <script language = "Javascript">
            function Validate(){
                var user=document.f1.user;
                var pass=document.f1.pass;
                var dealerID=document.f1.dealerID;
                var fname=document.f1.fname;
                var role=document.f1.role;
                var gender=document.f1.gender;
                var bday=document.f1.bday;
                var address=document.f1.address;
                var phone=document.f1.phone;
                var mail=document.f1.mail;
                var status=document.f1.status;
                
                if ((user.value==null)||(user.value=="")){
                    alert("Please enter User Name")
                    user.focus()
                    return false
                }
                
                if ((pass.value==null)||(pass.value=="")){
                    alert("Please enter Password")
                    pass.focus()
                    return false
                }
                
                if((dealerID.value==null)||(dealer.value=="")){
                    alert("Please choise DealerID")
                    dealerID.focus()
                    return false
                }
                
                if ((fname.value==null)||(fname.value=="")){
                    alert("Please enter Full Name")
                    fname.focus()
                    return false
                }
                
                if ((role.value==null)||(role.value=="")){
                    alert("Please choise Role")
                    role.focus()
                    return false
                }
                
                if ((gender.value==null)||(gender.value=="")){
                    alert("Please enter Gender")
                    gender.focus()
                    return false
                }
                
                if ((bday.value==null)||(bday.value=="")){
                    alert("Please enter Birthday")
                    bday.focus()
                    return false
                }
                
                if ((address.value==null)||(address.value=="")){
                    alert("Please enter Address")
                    address.focus()
                    return false
                }
                
                if ((phone.value==null)||(phone.value=="")){
                    alert("Please enter Phone Number")
                    phone.focus()
                    return false
                }
                
                var reg = /\d{10}/;
                if(!phone.value.match(reg))
                {
                    alert(phone.value+ " does not contain a valid code!");
                    phone.focus()
                    return false;
                }
                
                if ((mail.value==null)||(mail.value=="")){
                    alert("Please enter Mail")
                    mail.focus()
                    return false
                }
                
                if ((status.value==null)||(status.value=="")){
                    alert("Please enter Status")
                    status.focus()
                    return false
                }
                
            }
            
            function Delete() { 
                if (confirm("Are you sure you want to delete this Staff?")) { 
                    return true; 
                }else{ 
                    return false; 
                } 
            } 
        </script>
    </head>
    <body style="background-color: #bccbd8;">
        <%
            String user = (String) session.getAttribute("username");
            if (user == null) {
                session.setAttribute("error", "Please login!");
                response.sendRedirect("login.jsp");
            }
        %>
        <jsp:include page="banner.jsp"></jsp:include>
        <div id="leftcolumn">
            <jsp:include page="menuleft.jsp"></jsp:include>
            <img src="../images/navi_bg2.jpg" width="225" height="500" /><br />
        </div>

        <div id="content">            
            <table width="552">
                <tr>
                        <td><b>Account:</b></td>
                        <td><input name="stn" type="text"/></td>
                        <td><input type="submit" value="Search"/></td>
                </tr>
            </table>
            <%
                if (request.getParameter("stn") == null) {
                    int currPage = 1;
                    if (request.getParameter("p") == null) {
                        currPage = 1;
                    } else {
                        currPage = Integer.parseInt(request.getParameter("p"));
                    }
                    int recodperpage = 5;
                    functions f = new functions();
                    int count = f.countStaff();
                    int pagesize = 0;
                    int a = count / recodperpage;
                    int b = (count % recodperpage);
                    if (b == 0) {
                        pagesize = a;
                    } else {
                        pagesize = a + 1;
                    }
                    ResultSet rs = f.viewStaff();
            %>
            <table width="700px" style="text-align: left;">
                <tr>
                    <th>Staff account</th>
                    <th>Full name</th>
                    <th>Role</th>
                    <th>Gender</th>
                    <th>Birthday</th>                    
                    <th>Address</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Status</th>
                </tr> 
                <%

                    while (rs.next()) {
                        int id = rs.getInt("staffAcc");
                %>
                <tr>
                    <td> <%=rs.getString("staffAcc")%></td>
                    <td> <%=rs.getString("dealerID")%></td>
                    <td> <%=rs.getString("fullName")%></td>
                    <td> <%=rs.getString("role")%> </td>
                    <td> <%=rs.getString("gender")%> </td>
                    <td> <%=rs.getString("birthday")%> </td>
                    <td> <%=rs.getString("address")%> </td>
                    <td> <%=rs.getString("phone")%> </td>
                    <td> <%=rs.getString("mail")%> </td>
                    <td>
                        <%
                            int status = rs.getInt("status");
                            if (status == 1) {
                                out.print("Enable");
                            } else {
                                out.print("Disable");
                            }
                        %>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
